/*******************************************************************************
 * NEW Question FORM
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * Create a new topic
 */
qx.Class.define("bip.ui.questions.NewQuestionForm",
{
  extend : qx.ui.form.Form,
  
  construct : function()
  {
    this.base(arguments);
    // Add fields
    // IdLocal
    var localSelectfield = new bip.ui.form.LocalSelectBox();
    this.add(localSelectfield, "IdLocal", null, "idlocal");
    // TopicId
    var topicIdField = new qx.ui.form.Spinner();
    topicIdField.set({maximum: 10000,minimum: 0});
    this.add(topicIdField, "TopicId", null, "topicid");
    // Name
    var nameTextfield = new qx.ui.form.TextField();
    nameTextfield.setRequired(true);
    nameTextfield.setWidth(200);
    this.add(nameTextfield, "Name", null, "name");
    // Description
    var descTextfield = new qx.ui.form.TextField();
    descTextfield.setRequired(true);
    this.add(descTextfield, "Description", null, "description");
    // Min
    var minValueField = new qx.ui.form.Spinner();
    minValueField.set({maximum: 100,minimum: -100,value:0});
    this.add(minValueField, "MinValue", null, "minvalue");
    // Max
    var maxValueField = new qx.ui.form.Spinner();
    maxValueField.set({maximum: 100,minimum: -100,value:1});
    this.add(maxValueField, "MaxValue", null, "maxvalue");
    // Default
    var defaultValueField = new qx.ui.form.Spinner();
    defaultValueField.set({maximum: 1,minimum: 0,value:0});
    this.add(defaultValueField, "DefaultValue", null, "defaultvalue");
    
    // Logic
    // Make sure max is always upper min
    minValueField.addListener("changeValue",function(evt) {
    	if (evt.getData() >= maxValueField.getValue()) {
    		maxValueField.setValue(evt.getData()+1);
    	}
    	if (evt.getData() > defaultValueField.getValue()) {
    		defaultValueField.setValue(evt.getData());
    	}
    	defaultValueField.setMinimum(evt.getData());
    },this);
    // Make sure min is always below max
    maxValueField.addListener("changeValue",function(evt) {
    	if (evt.getData() <= minValueField.getValue()) {
    		minValueField.setValue(evt.getData()-1);
    	}
    	if (evt.getData() < defaultValueField.getValue()) {
    		defaultValueField.setValue(evt.getData());
    	}
    	defaultValueField.setMaximum(evt.getData());
    },this);
    
  },
  
	/*
	 *****************************************************************************
    MEMBERS
	 *****************************************************************************
	 */

 	members :
 	{
 		
 		
 	},
 	
	/*
	 * ****************************************************************************
	 * DESTRUCTOR
	 * ****************************************************************************
	 */

	destruct : function() {
		this._disposeObjects();
	}

  
});